<%@ page language="java" import="java.util.*,com.beans.*,net.sf.json.JSONArray,com.dao.*" pageEncoding="UTF-8"%>   
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>
  <head>
    <base href="<%=basePath%>">  
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="css/maintable.css" ></link>
	<script type="text/javascript"  src="js/jquery-1.8.0.js"></script>
	<style type="text/css">
			#adminName{
				width:200px;
			}
		</style>
		<script>
			$(function(){
				$(".one input[type=checkbox]").click(function(){
					if(this.checked){
						$("input[name="+$(this)[0].id+"]").attr("checked","checked");
					}else{
						$("input[name="+$(this)[0].id+"]").removeAttr("checked");
					}
				});
				
				$(".two input[type=checkbox]").click(function(){
					var name=$(this)[0].name;
					var list = document.getElementsByName(name);
					var flag=false;
					for(var i=0;i<list.length;i++){
						if(list[i].checked==true){
							flag=true;
							$(".one input[id="+name+"]").attr("checked","checked");
							return ;
						}
					}
					if(flag==false){
						$(".one input[id="+name+"]").removeAttr("checked");
					}
				});
				
				var addAndDelete = '${addAndDelete}';
				if(addAndDelete!=""){
					$("#result").html(addAndDelete);
				}
			});
			function tiJiao(){
				$("input[type=checkbox]").attr("name","chec");
				return confirm("确认要提交吗");
			}
		</script>
  </head>
  
  <body>
  		 <div class ="div_title">
				<div class="div_titlename"> <img src="images/san_jiao.gif" ><span>权限管理分配 -->当前权限管理员为：${roleInfo.roleName }</span></div>
				<div class="div_titleoper">
				</div>
		</div>
		<form action="RoleServlet.do" method="post">
		<input type="hidden" name="flag" value="xiugai">
		<input type="hidden" name="roleId" value="${roleInfo.id }">
			<table class="main_table" >
			       <tr>
			 				<th id="adminName">一级菜单</th> 	<th>二级菜单</th>	
			 		</tr>
			 		<c:forEach var="menu" items="${ menuList}" varStatus="td">
			 			<tr>
			 				<td class="one">
			 						<input type="checkbox" name="chec" value="${menu.id }" id="${menu.id }" >${menu.menuName }_${menu.id }<br/>
			 				</td>
			 				<td id="${menu.id }" class="two">
				 				<c:forEach var="smenu" items="${menu.subMenuList }">
					 				<input type="checkbox"  name="${menu.id }" value="${smenu.id }" id="${smenu.id }" >${smenu.menuName }-${smenu.id }<br/>
				 				</c:forEach>
				 			</td>
			 			</tr>
			 		</c:forEach>
			 		<tr>
			 			<td></td>
			 			<td>
			 				<input type="submit" value="保存修改" onclick="return tiJiao()"><label id="result"></label>
			 			</td>
			 		</tr>
			</table>
		</form>
		<!-- 做菜单栏的回显 -->
		<script type="text/javascript">
			var roleMenuStr = '${roleMenuStr}';
			if(roleMenuStr!=""){
				var roleMenuStrArray = roleMenuStr.split(",");
				for(var i=0; i<roleMenuStrArray.length;i++){
					$("#"+roleMenuStrArray[i]).attr("checked","checked");
				}
			}
		</script>
  </body>
</html>